package lib

import (
	"encoding/json"
	"fmt"
	"strconv"
	"strings"
)

type BigInt struct {
	Data string
}

/**
 * @author feige
 * @date 2023-10-15
 * @version 1.0
 * @desc 序列化方法
 */
func (t *BigInt) MarshalJSON() ([]byte, error) {
	stamp := fmt.Sprintf("\"%s\"", t.Data)
	return []byte(stamp), nil
}

/**
 * @author feige
 * @date 2023-10-15
 * @version 1.0
 * @desc 反序列化
 */
func (t *BigInt) UnmarshalJSON(data []byte) error {
	t.Data = strings.ReplaceAll(string(data), "\"", "")
	return nil
}

// String 重写String方法
func (t *BigInt) String() string {
	data, _ := json.Marshal(t)
	return string(data)
}

/**
 * 获取具体的数值
 * @author feige
 * @date 2023-11-22
 * @version 1.0
 * @desc
 */
func (t *BigInt) Uint64() uint64 {
	value, _ := strconv.ParseUint(t.Data, 10, 64)
	return value
}
